<template>
  <div class="container">
    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
        <span style="margin-left: 20px; margin-right: 6px;">日期:</span>
        <IDatePicker :showTime="false" style="margin-left: 10px;" placeholder="不选则不限制" v-model="filter.min_day"></IDatePicker>
        至
        <IDatePicker :showTime="false" style="margin-left: 0px;" placeholder="不选则不限制" v-model="filter.max_day"></IDatePicker>

      </div>
    </div>
    <a-table class="table" :rowKey="row => row.id" :dataSource="list">
      <a-table-column title="封面" width="80px">
          <template slot-scope="row">
            <img class="thumb" :src="row.thumb + '?x-oss-process=image/resize,w_250'">
          </template>
        </a-table-column>
      <a-table-column title="商品" >
        <template slot-scope="row">
          <div>{{row.title}}</div>
          <div><PriceDisplay :info="row"></PriceDisplay>*{{row.total}}</div>
        </template>
      </a-table-column>
      <a-table-column title="收益" width="100px">
        <template slot-scope="row">
          <div>+{{formatPrice(row.sy)}}</div>
        </template>
      </a-table-column>
      <a-table-column title="日期" width="180px">
        <template slot-scope="row">
          <div>{{row.created_at}}</div>
        </template>
      </a-table-column>
      <a-table-column title="来源">
        <template slot-scope="row">
          <div>{{row.node_title}}</div>
          <div v-if="row.number">订单号:{{row.number}}</div>
        </template>
      </a-table-column>
      <a-table-column title="备注" width="160px">
        <template slot-scope="row">
          <a-tag>{{ row.node_type_text }}</a-tag>
          <template v-if="row.options && row.options.shang_title">
            <a-tag color='blue' v-if="row.options.shang_type === 0">{{ row.options.shang_title }}</a-tag>
            <a-tag color='orange' v-else>{{ row.options.shang_title }}</a-tag>
          </template>
          <template v-if="row.options && row.options.is_hidden_sku">
            <a-tag color='orange'>隐藏款</a-tag>
          </template>
          <div v-if="row.open_index">
             抽取号
            <template v-if="row.open_indexs && row.open_indexs.length > 1">{{row.open_indexs}}</template>
            <template v-else>{{row.open_index}}</template>
          </div>
          <div v-if="row.options && row.options.room_num">房间号 {{row.options.room_num}}</div>
        </template>
      </a-table-column>
    </a-table>


  </div>
</template>

<script>
  import { getSysearchList } from '@/api/visitors'
  import moment from 'moment'
  import IDatePicker from "@/components/IDatePicker/IDatePicker.vue"

  export default {
    components: {
      IDatePicker
    },
    data() {
      return {
        info: {},
        list: [],
        filter: {
          min_day: '',
          max_day: ''
        }
      }
    },
    computed: {
    },
    props: {
      user_id: 0,
    },
    created() {
      this.fetchData();
    },
    filters: {
      formatDate (value) {
        return value ? moment(value).fromNow() : ''
      },
      formatDate2 (value) {
        return value ? moment(value).format('YYYY-MM-DD') : ''
      }
    },
    mounted() {},
    watch: {
      'filter.min_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.fetchData()
        }
      },
      'filter.max_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.fetchData()
        }
      }
    },
    methods: {
      formatPrice(price) {
        return (price / 100).toFixed(2)
      },
       fetchData () {
        getSysearchList({
          user_id:this.user_id,
          min_day: this.filter.min_day,
          max_day: this.filter.max_day,
        }).then(res => {
          this.list = res.data.list
        })
      },
      cancel() {
        this.$router.back(-1)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .thumb {
      width: 40px;
      height: 40px;
      object-fit: contain;
    }

  .headimg {
    width: 28px;
    height: 28px;
    border-radius: 50%;
  }


  .form-container {
    padding-bottom: 120px;
  }

  .container {
    .btn {
      margin-right: 30px;
    }
  }

  .tips-c {
    margin-bottom: 20px;
    font-weight: 500;
  }
</style>
